#ifndef __BSP_TEMP_HUMI_HANDLER_H
#define __BSP_TEMP_HUMI_HANDLER_H

#include "cmsis_os.h"
#include "stdio.h"
#include "stdint.h"
#include "stdbool.h"
#include "bsp_aht21_driver.h"

typedef enum
{
    TEMP_HUMI_EVENT_DATA_TYPE_TEMPERATURE,
    TEMP_HUMI_EVENT_DATA_TYPE_HUMIDITY,
    TEMP_HUMI_EVENT_DATA_TYPE_BOTH
}temp_humi_handler_event_data_type_t;

//app层传来的参数
typedef struct 
{
    float *  temp;        //温度
    float *  humi;        //湿度
    uint32_t lifetime;    //数据新鲜度
    uint32_t timestamp;   //发送事件时间戳
    temp_humi_handler_event_data_type_t    type;  //数据类型
    void (*pfcallback)(float* temp, float* humi);  //回调函数
}temp_humi_handler_event_t;

//handler层需要的接口
typedef struct
{   uint32_t (*pfget_tick)(void);
    void     (*pfos_delay_ms) (uint32_t ms);
    int8_t   (*pfqueue_create)(uint32_t item_num,  uint32_t item_size,  void **queue_handle);
    int8_t   (*pfqueue_put)   (void *queue_handle, void *item,          uint32_t timeout);
    int8_t   (*pfqueue_get)   (void *queue_handle, void *msg,           uint32_t timeout);
}temp_humi_handler_os_interface_t;

//集合传递的参数
typedef struct{
    iic_driver_interface_t            *iic_driver_interface;
    yield_interface_t                 *yield_interface;
    irq_interface_t                   *irq_interface;
    temp_humi_handler_os_interface_t  *temp_humi_handler_os_interface;
}temp_humi_handler_all_input_arg_t;

/*集合结构体*/
typedef struct
{   
    //传入driver层接口
    iic_driver_interface_t            *iic_interface;
    yield_interface_t                 *yield_interface;
    irq_interface_t                   *irq_interface;
    //传入handler层接口
    temp_humi_handler_os_interface_t  *os_interface;
    //本层接口

    //driver层实例
    bsp_aht21_driver_t                *aht21_instance;

    //队列句柄
    void *event_queue_handler;
    //handler是否初始化完成标志
    bool inited;
    //获取温度是tick值
    uint32_t last_temp_tick;
    //获取湿度时tick值
    uint32_t last_humi_tick;
}bsp_temp_humi_handle_t;

/*构造函数 */
int8_t inst_handler(bsp_temp_humi_handle_t *temp_humi_handle, temp_humi_handler_all_input_arg_t *all_args);
/*对app层提供的函数 */
int8_t bsp_temp_humi_read(temp_humi_handler_event_t *event);

#endif

